close
clear

mux = 0;
sigmax = 1;

xSample = normrnd(mux, sigmax, 1e6, 1);
ySample = g(xSample);
subplot(2, 1, 1)
histogram(ySample, 'Normalization', 'pdf', ...
    'BinLimits', [0, 5], 'BinWidth', .1)

y = 0:.01:5;
py = 1/sqrt(2*pi*sigmax^2)*exp(-1/2*log(y).^2/(sigmax^2)).*(1./y);
hold on
plot(y, py)

%Linearization
muy = g(mux);
yApproximate = dg(mux) * (xSample - mux) + muy;
subplot(2, 1, 2)
histogram(yApproximate, 'Normalization', 'pdf', ...
    'BinWidth', .1)

function y = g(x)
    y = exp(x);
end

function y = dg(x)
    y = exp(x);
end
